<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <table border="1" cellspacing="0" width="300px">
        <thead>
            <tr>
                <th>ID</th>
                <th>姓名</th>
                <th>性别</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
    <script>
        var datas = [
            {id:1,name:'dai',age:'18'},
            {id:2,name:'wen',age:'19'},
            {id:3,name:'wen',age:'20'}
        ];
        var tbody = document.querySelector('tbody');
        datas.forEach(function(item){
            var tr =document.createElement("tr");
            tbody.append(tr);
            for(var k in item){
                var td = document.createElement("td");
                td.innerText = item[k];
                tr.append(td);
            }
            var td = document.createElement("td")
            td.innerHTML = "<span>删除</span>"
            tr.append(td);
        })
        var spans = document.querySelectorAll("span");
        for(var i =0;i<spans.length;i++){
            spans[i].onclick = function(){
                tbody.removeChild(this.parentNode.parentNode)
            }
        }
    </script>
</body>
</html>